home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / amigalib / createport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-09  |  1.5 KB  |  74 lines

  1.  
  2. /*
  3.  *  CreatePort.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/ports.h>
  13. #include <exec/memory.h>
  14. #ifdef INCLUDE_VERSION        /*    2.0 */
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17. #else
  18. extern void *AllocMem(long, long);
  19. extern void FreeMem(void *, long);
  20. extern void NewList(struct List *);
  21. extern void AddPort(struct MsgPort *);
  22. extern void RemPort(struct MsgPort *);
  23. extern int AllocSignal(int);
  24. extern void FreeSignal(int);
  25. extern void *FindTask(char *);
  26. #endif
  27.  
  28. #ifndef HYPER
  29. #define HYPER
  30. #endif
  31.  
  32. typedef struct MsgPort    MsgPort;
  33.  
  34. MsgPort *
  35. HYPER ## CreatePort(name, pri)
  36. UBYTE *name;
  37. long pri;
  38. {
  39.     MsgPort *port;
  40.  
  41.     if (port = AllocMem(sizeof(MsgPort), MEMF_PUBLIC | MEMF_CLEAR)) {
  42.     if ((char)(port->mp_SigBit = AllocSignal(-1)) >= 0) {
  43.         port->mp_Node.ln_Pri = pri;
  44.         port->mp_Node.ln_Type = NT_MSGPORT;
  45.         port->mp_Node.ln_Name = name;
  46.         port->mp_Flags   = PA_SIGNAL;
  47.         port->mp_SigTask = FindTask(NULL);
  48.         NewList(&port->mp_MsgList);
  49.         if (name)
  50.         AddPort(port);
  51.     } else {
  52.         FreeMem(port, sizeof(MsgPort));
  53.         port = NULL;
  54.     }
  55.     }
  56.     return(port);
  57. }
  58.  
  59. void
  60. DeletePort(port)
  61. MsgPort *port;
  62. {
  63.     if (port) {
  64.     if (port->mp_Node.ln_Name)
  65.         RemPort(port);
  66.     if ((port->mp_Flags & PF_ACTION) == PA_SIGNAL) {
  67.         FreeSignal(port->mp_SigBit);
  68.         port->mp_Flags = PA_IGNORE;
  69.     }
  70.     FreeMem(port, sizeof(MsgPort));
  71.     }
  72. }
  73.  
  74.